package com.share.hope.controller;

import com.share.hope.entity.ProductsInfo;
import com.share.hope.entity.page.PageQueryVo;
import com.share.hope.entity.result.PageR;
import com.share.hope.entity.result.R;
import com.share.hope.service.ProductsService;
import com.share.hope.vo.ProductsPageQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/share/hope/products")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "商品信息管理接口")
@CrossOrigin
public class ProductsController {

    private final ProductsService productsService;

    @PostMapping("/create")
    @Operation(summary = "添加商品")
    public R<String> createProduct(@RequestBody ProductsInfo productsInfo) {
        return productsService.createProduct(productsInfo);
    }

    @PostMapping("/update")
    @Operation(summary = "修改商品")
    public R<String> updateProduct(@RequestBody ProductsInfo productsInfo) {
        return productsService.updateProduct(productsInfo);
    }

    @GetMapping("/delete")
    @Operation(summary = "刪除商品")
    public R<String> deleteProduct(@RequestParam Long productId) {
        return productsService.deleteProduct(productId);
    }

    @PostMapping("/page")
    @Operation(summary = "分頁查詢商品")
    public R<PageR<ProductsInfo>> pageProduct(@RequestBody PageQueryVo<ProductsPageQueryVo> queryVo) {
        return productsService.pageProduct(queryVo);
    }

    @GetMapping("/exchange")
    @Operation(summary = "兑换商品")
    public R<String> exchangeCollect(@RequestParam Long userId, @RequestParam Long productId) {
        return productsService.exchangeCollect(userId, productId);
    }
}
